import { mapGetters } from 'vuex'
export default {
  computed: {
    ...mapGetters('m_cart', ['selectedSum'])
  },
  watch: {
    selectedSum(newVal) {
      this.setBadge();
    }
  },
  onShow() {
    this.setBadge()
  },
  methods: {
    setBadge(){
      if (this.selectedSum > 0) {
        uni.setTabBarBadge({
          index: 2, // 购物车 tabBar 的索引
          text: this.selectedSum + '', // 必须转成字符串
        })
      } else {
          uni.removeTabBarBadge({ index: 2 }) // 如果数量为 0，移除角标
        }
    }
  }
}